# Maintainer: Nazar Mishturak <nazar m x at gmail dot com>

_realname=libbotan
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.14.0
pkgrel=1
arch=('any')
url='https://botan.randombit.net/'
pkgdesc='Botan is a C++ cryptography library released under the permissive Simplified BSD license (mingw-w64)'
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-xz")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-imagesize")
             #"${MINGW_PACKAGE_PREFIX}-doxygen"
             #"${MINGW_PACKAGE_PREFIX}-graphviz")
license=('BSD')
options=('strip' 'staticlibs' 'docs')
source=(https://botan.randombit.net/releases/Botan-${pkgver}.tar.xz{,.asc}
        '001-boost-link.patch'
        '002-winsock-link.patch'
        '003-python3-install.patch')
noextract=("Botan-${pkgver}.tar.xz")
sha256sums=('0c10f12b424a40ee19bde00292098e201d7498535c062d8d5b586d07861a54b5'
            'SKIP'
            'c4dfd71c7e6a9592e2a95634e3fabfc071c1110a96ba218c4a3565fa14cb34da'
            '12f676d9c8f66decd7dc52a6a70f0c044737636837c79ae02f96d8d5a2168c46'
            '4c3160fcb47791c34984d2ada5cdb6f0dfc029dfe39822ba969d4672dc2fa170')
validpgpkeys=('621DAF6411E1851C4CF9A2E16211EBF1EFBADFBC')

prepare() {
  cd "${srcdir}"
  # Tarball contains Botan-${pkgver}.tgz/.travis.yml symlink
  bsdtar -xJf "Botan-${pkgver}.tar.xz" || true
  cd "Botan-${pkgver}"
  patch -p1 -i "${srcdir}/001-boost-link.patch"
  patch -p1 -i "${srcdir}/002-winsock-link.patch"
  patch -p1 -i "${srcdir}/003-python3-install.patch"
}

build() {
  rm -rf build-${MINGW_CHOST}
  cp -rf Botan-${pkgver} build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  sed -i "s|/mingw|${MINGW_PREFIX}|g" src/build-data/os/mingw.txt

  local BUILD_TYPE_FLAGS=''
  if check_option 'debug' 'y'; then
    BUILD_TYPE_FLAGS='--with-debug-info'
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=;--libdir=;--bindir=" \
  ${MINGW_PREFIX}/bin/python configure.py \
    --disable-shared \
    --os=mingw \
    --cc=gcc \
    --prefix=${MINGW_PREFIX} \
    --cpu=${CARCH} \
    ${BUILD_TYPE_FLAGS} \
    --link-method=copy \
    --without-doxygen \
    --with-sphinx \
    --without-rst2man \
    --with-boost \
    --with-openmp \
    --with-bzip2 \
    --with-lzma \
    --with-sqlite3 \
    --with-zlib

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./botan-test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--libdir=;--bindir=" \
  DESTDIR="${pkgdir}" \
  make install
}
